<template>
  <el-dialog
    title="重命名"
    :visible.sync="visible"
    width="500px"
    :before-close="handleClose"
  >
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="简历名称" prop="newName">
        <el-input
          v-model="ruleForm.newName"
          placeholder="请输入新的简历名称"
        ></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="handleClose">取 消</el-button>
      <el-button size="small" type="primary" @click="handleConfirm"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>

<script>
export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    file: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      ruleForm: {
        newName: ''
      },
      rules: {
        newName: [
          { required: true, message: '请输入简历名称', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    handleClose() {
      this.$emit('update:visible', false);
    },
    handleConfirm() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.$emit('confirm', this.ruleForm.newName);
        } else {
          return false;
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .el-dialog__body {
  padding: 24px 24px 0 0;
  border-top: 1px solid #ececec;
  border-bottom: 1px solid #ececec;
}
::v-deep .el-dialog__footer {
  padding: 20px;
}
</style>
